home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 April / Software of the Month Club 1996 April.iso / pc / os2 / psutils / cmd / showchar.cmd < prev   
Encoding:
Text File  |  1996-02-21  |  2.7 KB  |  126 lines

  1. extproc sh \psutils\showchar.cmd 
  2. #!/bin/sh
  3. # showchar: show character with information
  4. #
  5. # Copyright (C) Angus J. C. Duggan 1991-1995
  6. # See file LICENSE for details.
  7. shift 
  8. # See file LICENSE for details.
  9. #
  10. # usage:
  11. #       showchar Font-Name Char-Name | lpr -Pprinter
  12.  
  13. if [ $# != 2 ]; then
  14.         echo "Usage: `basename $0` Font-Name Char-Name" >&2
  15.         exit 1
  16. fi
  17.  
  18. cat <<EOF
  19. %!
  20. % Get character metrics and bounding box for $1
  21. /ns 30 string def
  22. /fname /$1 def
  23. /cname /$2 def
  24. /fn fname findfont 1000 scalefont def
  25. /thin 0.7 def
  26. /reduction 2.0 def
  27.  
  28. /sn { ns cvs show } def
  29. /sc { (\()show exch sn (,)show sn (\))show } def
  30.  
  31. /Times-Roman findfont 10 scalefont setfont
  32.  
  33. 72 242 translate % one inch in, 3 1/2 inch up
  34. newpath 0 0 moveto
  35. gsave   % print character name
  36.    0 468 rmoveto
  37.    ($2 from font $1 displayed on `date` by `basename $0` 1.00 (C) AJCD 1991)
  38.    show 
  39. grestore
  40.  
  41. gsave
  42.    thin setlinewidth  % cross hairs
  43.    -9 0 rmoveto 18 0 rlineto
  44.    -9 -9 rmoveto 0 18 rlineto
  45.    stroke  % position info
  46.    -9 -9 moveto ((0,0)) stringwidth pop neg 0 rmoveto
  47.    ((0,0)) show
  48. grestore
  49.  
  50. % create encoding with a single character at all positions
  51. /MyEncoding 256 array def
  52.  
  53. 0 1 255 { % fill out with notdefs
  54.    MyEncoding exch cname put
  55. } for
  56.  
  57. fn dup length dict begin
  58.   {1 index /FID ne {def} {pop pop} ifelse} forall
  59.   /Encoding MyEncoding def
  60.   currentdict
  61. end /newfont exch definefont
  62. /fn exch def
  63. /en MyEncoding def
  64.  
  65. gsave  % draw character (enlarged)
  66.   .75 setgray
  67.   fn 1 reduction div scalefont setfont
  68.   (\000) show
  69. grestore
  70.  
  71. % show character info
  72. fn /Metrics known {
  73.    dup fn /Metrics get exch get 
  74.    dup type /arraytype eq {
  75.       dup length 2 eq
  76.       {1 get 0} {dup 2 get exch 3 get} ifelse
  77.    } {
  78.       round 0
  79.    } ifelse
  80. } {
  81.    gsave
  82.       fn setfont (\000) stringwidth round exch round exch
  83.    grestore
  84. } ifelse
  85. gsave   % show width
  86.    thin setlinewidth
  87.    2 copy
  88.    reduction div exch reduction div exch rlineto
  89.    gsave
  90.       1 1 rmoveto sc
  91.    grestore
  92.    -4 -3 rlineto 0 6 rmoveto 4 -3 rlineto
  93.    stroke
  94. grestore
  95.  
  96. gsave
  97.    gsave  % get bounding box
  98.       fn setfont
  99.       (\000) true charpath flattenpath pathbbox
  100.    grestore
  101.    thin setlinewidth
  102.    3 index reduction div  % put coords on top of stack
  103.    3 index reduction div
  104.    3 index reduction div
  105.    3 index reduction div
  106.    3 index 3 index moveto
  107.    gsave  % llx lly
  108.       0 -9 rmoveto 7 index 7 index sc
  109.    grestore
  110.    1 index 3 index lineto
  111.    gsave  % urx lly
  112.       0 -9 rmoveto 5 index 7 index sc
  113.    grestore
  114.    1 index 1 index lineto
  115.    gsave  % urx ury
  116.       0 9 rmoveto 5 index 5 index sc
  117.    grestore
  118.    3 index 1 index lineto
  119.    gsave  % llx ury
  120.       0 9 rmoveto 7 index 5 index sc
  121.    grestore
  122.    closepath stroke
  123. grestore
  124. showpage
  125. EOF
  126.